﻿namespace KinonekoSoftware.Studio.Models.Instances.Team
{
    public sealed class TeamConnectionPresenter : ObservableObject
    {

        public TeamConnectionPresenter(TeamKizuna target)
        {
            Target   = target ?? throw new ArgumentNullException(nameof(target));
            ListOfEX = new ObservableCollection<InstanceCache>();
        }
        
        
        public void Initialize(InstanceCacheEngine engine)
        {
            
            if (!string.IsNullOrEmpty(Target.Protagonist))
            {
                Protagonist = engine.Get(Target.Protagonist);
            }

            if (!string.IsNullOrEmpty(Target.Current))
            {
                Current = engine.Get(Target.Current);
            }

            foreach (var ex in Target.ListOfEX)
            {
                ListOfEX.Add(engine.Get(ex));
            }
            
            RaiseUpdated(nameof(Protagonist));
            RaiseUpdated(nameof(Current));
        }


        public string                              Id          => Target.Id;
        public TeamKizuna                          Target      { get; }
        public InstanceCache                       Protagonist { get; private set; }
        public InstanceCache                       Current     { get; private set; }
        public ObservableCollection<InstanceCache> ListOfEX    { get; }
    }
}